package com.gitee.qdbp.jdbc.plugins.impl;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.gitee.qdbp.able.jdbc.model.PkEntity;
import com.gitee.qdbp.jdbc.model.DbVersion;
import com.gitee.qdbp.jdbc.plugins.DbPluginHelper;

/**
 * 批量操作基础类
 *
 * @author zhaohuihua
 * @version 20210626
 */
public abstract class BatchBaseExecutor implements DbPluginHelper.Aware {

    protected DbPluginHelper plugins;
    private final String defaultSupports;

    public BatchBaseExecutor(String versionSupports) {
        this.defaultSupports = versionSupports;
    }

    public boolean supports(DbVersion version) {
        String key = "supports." + this.getClass().getSimpleName();
        return plugins.configSupports(key, defaultSupports, version);
    }

    @Override
    public void setPlugins(DbPluginHelper plugins) {
        this.plugins = plugins;
    }

    protected final Set<String> mergeFields(List<PkEntity> entities) {
        Set<String> fieldNames = new HashSet<>();
        for (PkEntity item : entities) {
            fieldNames.addAll(item.getEntity().keySet());
        }
        return fieldNames;
    }
}
